package com.lycos.ludrien.client;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;

public class ListePara {
	
	private class Para{
	
		public String Chemin;
		public String NomDoc;
		public int Taille;
		
		public Para(String p_chemin, String p_doc, int p_taille){
			this.Chemin = p_chemin;
			this.NomDoc = p_doc;
			this.Taille = p_taille;
		}
		
	}
	
	private HashMap<Integer, Para> listeParagraphe;
	
	public ListePara(Connection con){
	
		HashMap<Integer, String> listeDocs = new HashMap<Integer, String>();
		listeParagraphe = new HashMap<Integer, ListePara.Para>();
		listeParagraphe.clear();

		try {
			

			String req = "Select * from document";
			PreparedStatement pstmt = con.prepareStatement(req);
			ResultSet rs = pstmt.executeQuery();

			while (rs.next()){
				listeDocs.put(rs.getInt(1), rs.getString(2));
			}

			req = "Select * from paragraphe";
			pstmt = con.prepareStatement(req);
			rs = pstmt.executeQuery();

			while (rs.next()){				
				Para p = new Para(rs.getString(2), listeDocs.get(rs.getInt(3)), rs.getInt(4));
				listeParagraphe.put(rs.getInt(1), p);
			}

		}catch (Exception e){}
	}
	
	public String getChemin(int ID){
		return listeParagraphe.get(ID).Chemin;
	}
	
	public String getNomDoc(int ID){
		return listeParagraphe.get(ID).NomDoc;
	}

	public int getTailleDoc(int ID){
		return listeParagraphe.get(ID).Taille;
	}
	
	public ArrayList<Integer> getArrayIdPara(){
		ArrayList<Integer> listeIds = new ArrayList<Integer>();
		
		for (int id: listeParagraphe.keySet()){
			listeIds.add(id);
		}
		
		return listeIds;
	}
}
